/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2012
 */

package com.tudou.searchcontrol.service.impl;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.tudou.searchcontrol.model.PageInfo;

import com.tudou.searchcontrol.dao.VideoDao;
import com.tudou.searchcontrol.model.Video;
import com.tudou.searchcontrol.service.IVideoService;

@Service("videoService")
public class VideoService implements IVideoService {

	@Autowired
	private VideoDao videoDao;
	
	public PageInfo getVideoByPage(Map searchMap,PageInfo pageInfo){
		return videoDao.getObjectPageInfo(searchMap,pageInfo);
	}
	
	public List<Video> getVideoList(Map searchMap){
		return videoDao.getObjectList(searchMap);
	}
	
	public int saveOrUpdateVideo(Video video){
		if(video.getId() == null){
			return videoDao.addObject(video);
		}else{
			return videoDao.updateObject(video);
		}
	}
	
	public Video getVideoById(Long id){
		return videoDao.getObjectById(id);
	}
	
	public int deleteVideo(String ids){
		int delNum = 0;
		if(StringUtils.isNotEmpty(ids)){
			String[] idstr = ids.split(",");
			for(int i=0;i<idstr.length;i++){
				delNum = videoDao.deleteObject(Long.valueOf(idstr[i]));
			}
		}
		return delNum;
	}
	

}
